package gui.panel_new.conexion;

import enums.TextBundleEnum;
import enums.URLEnum;
import misc.BundlesProvider;

import javax.swing.*;
import java.awt.*;
import java.util.ResourceBundle;
/*

    This file is part of Logica-Logike.

    Logica-Logike is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation version 3 of the License.

    Logica-Logike is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Logica-Logike.  If not, see <http://www.gnu.org/licenses/>.

 */
/**
 * Extension de JPanel refiere a los datos de conexion necesarios para conectar un cliente;
 *
 * @author Jose Martin Rozanec;
 */
public class ClientConnectionPanel extends JPanel {
    private JLabel namesLabel;
    private JLabel surnamesLabel;
    private JLabel studentsNumberLabel;
    private JLabel ipLabel;
    private JTextField namesField;
    private JTextField surnamesField;
    private JTextField studentsNumberField;
    private JTextField ipField;
    private JButton connectButton;

    private ResourceBundle textBundle;

    /**
     * Constructor;
     */
    public ClientConnectionPanel() {
        initComponents();
        layoutComponents();
    }

    /**
     * Inicializa los componentes de ClientConnectionPanel;
     */
    private void initComponents() {
        textBundle = BundlesProvider.getBundle(URLEnum.TEXT_BUNDLE);
        namesLabel = new JLabel(textBundle.getString(TextBundleEnum.NAMES.toString()));
        surnamesLabel = new JLabel(textBundle.getString(TextBundleEnum.SURNAMES.toString()));
        studentsNumberLabel = new JLabel(textBundle.getString(TextBundleEnum.STUDENT_NUMBER.toString()));
        ipLabel = new JLabel(textBundle.getString(TextBundleEnum.IP.toString()));
        namesField = new JTextField(20);
        surnamesField = new JTextField(20);
        studentsNumberField = new JTextField(18);
        ipField = new JTextField(15);
        connectButton = new JButton(textBundle.getString(TextBundleEnum.CONNECT.toString()));
    }

    /**
     * Dispone los elementos visuales del ClientConnectionPanel;
     */
    private void layoutComponents() {
        setBackground(Color.WHITE);
        setLayout(new GridBagLayout());
        GridBagConstraints gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.insets = new Insets(0, 2, 2, 3);
        gridBagConstraints.gridwidth = 3;
        add(getLabelFieldPanel(namesLabel, namesField), gridBagConstraints);
        gridBagConstraints.gridy = 1;
        add(getLabelFieldPanel(surnamesLabel, surnamesField), gridBagConstraints);
        gridBagConstraints.gridy = 2;
        add(getLabelFieldPanel(studentsNumberLabel, studentsNumberField), gridBagConstraints);
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 1;
        add(ipLabel, gridBagConstraints);
        gridBagConstraints.gridx = 1;
        add(ipField, gridBagConstraints);
        gridBagConstraints.gridx = 2;
        add(connectButton, gridBagConstraints);
    }

    /**
     * Devuelve un panel que contenga el JLabel y JTextField pasados como referencia al metodo;
     *
     * @param label;
     * @param field;
     * @return JPanel;
     */
    private JPanel getLabelFieldPanel(JLabel label, JTextField field) {
        JPanel panel = new JPanel();
        panel.add(label);
        panel.add(field);
        panel.setBackground(Color.WHITE);
        return panel;
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame();
        frame.setContentPane(new ClientConnectionPanel());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }
}
